/**
 * Copyright (c) 2007 lyxite.com
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a 
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
using System;
using System.Runtime.InteropServices;

namespace Weys.Lib
{
	public class WinAPI
	{
		
		public const int GWL_EXSTYLE = -20;

		public enum ClassStyle
		{
			DropShadow = 0x00020000
		}

		public enum Bool 
		{
			False = 0,
			True
		};

		[StructLayout(LayoutKind.Sequential)]
			public struct Point 
		{
			public Int32 x;
			public Int32 y;

			public Point(Int32 x, Int32 y) { this.x= x; this.y= y; }
		}

		[StructLayout(LayoutKind.Sequential)]
			public struct Size 
		{
			public Int32 cx;
			public Int32 cy;

			public Size(Int32 cx, Int32 cy) { this.cx= cx; this.cy= cy; }
		}

		[StructLayout(LayoutKind.Sequential, Pack=1)]
			struct ARGB 
		{
			public byte Blue;
			public byte Green;
			public byte Red;
			public byte Alpha;
		}

		[StructLayout(LayoutKind.Sequential, Pack=1)]
			public struct BLENDFUNCTION 
		{
			public byte BlendOp;
			public byte BlendFlags;
			public byte SourceConstantAlpha;
			public byte AlphaFormat;
		}


		public const Int32 ULW_COLORKEY = 0x00000001;
		public const Int32 ULW_ALPHA    = 0x00000002;
		public const Int32 ULW_OPAQUE   = 0x00000004;

		public const byte AC_SRC_OVER  = 0x00;
		public const byte AC_SRC_ALPHA = 0x01;

		public const Int64  RGN_AND = 1;
		public const Int64  RGN_OR = 2;
		public const Int64  RGN_XOR = 3;
		public const Int64  RGN_DIFF = 4;
		public const Int64  RGN_COPY = 5;

		[DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]
		public static extern Bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);

		[DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]
		public static extern IntPtr GetDC(IntPtr hWnd);

		[DllImport("user32.dll", ExactSpelling=true)]
		public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

		[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
		public static extern IntPtr CreateCompatibleDC(IntPtr hDC);

		[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
		public static extern Bool DeleteDC(IntPtr hdc);

		[DllImport("gdi32.dll", ExactSpelling=true)]
		public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);

		[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
		public static extern Bool DeleteObject(IntPtr hObject);

		[DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]
		public static extern long SetWindowLong(IntPtr hWnd,int nIndex, long dwNewLong);

		[DllImport("User32.dll", CharSet=CharSet.Auto)] 
		public static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw); 

		[DllImport("Gdi32.dll", CharSet=CharSet.Auto)] 
		public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);

		[DllImport("Gdi32.dll", CharSet=CharSet.Auto)] 
		public static extern int CombineRgn(IntPtr destRgn, IntPtr srcRgn1, IntPtr srcRgn2, Int64 flag);
		
		[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
		public static extern bool BitBlt(
			IntPtr hdcDest, // handle to destination DC
			int nXDest,  // x-coord of destination upper-left corner
			int nYDest,  // y-coord of destination upper-left corner
			int nWidth,  // width of destination rectangle
			int nHeight, // height of destination rectangle
			IntPtr hdcSrc,  // handle to source DC
			int nXSrc,   // x-coordinate of source upper-left corner
			int nYSrc,   // y-coordinate of source upper-left corner
			System.Int32 dwRop  // raster operation code
			);

		[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
		public static extern IntPtr CreateDC(
			string lpszDriver,        // driver name
			string lpszDevice,        // device name
			string lpszOutput,        // not used; should be NULL
			IntPtr lpInitData	// optional printer data
			);
	}
}